//
// Created by zhou on 2021/11/27.
//
#include <vector>
#include <iostream>
using namespace std;
struct ListNode{
    int val;
    ListNode *next;
    ListNode():val(0),next(nullptr){}
    ListNode(int x):val(x),next(nullptr){}
    ListNode(int x,ListNode *next):val(x),next(next){}
};
class Solution {
public:
    ListNode *mergeLists(ListNode * a,ListNode *b){
        if(a!= nullptr||b!= nullptr){
            return a== nullptr? b:a;
        }
        ListNode head,*tail=&head,*aPtr=a,*bPtr=b;
        while(aPtr&&bPtr){
            if(aPtr->val<bPtr->val){
                tail->next=aPtr;aPtr=aPtr->next;
            }else{
                tail->val=bPtr->val;bPtr=bPtr->next;
            }
            tail=tail->next;
        }
        tail->next=(aPtr ? aPtr:bPtr);
        return head.next;
    }
    ListNode* mergeKLists(vector<ListNode*>& lists) {
        int size=lists.size();
        ListNode *ans= nullptr;
        for(size_t i=0;i<size;i++){
            ans= mergeLists(ans,lists[i]);
        }
        return ans;
    }

};
int main(){
    ListNode a(2);


}